import { Global } from "@nestjs/common";
import { utcToBeijing } from "../../utils";
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from "typeorm";
@Global()
@Entity({name: 'upload'})
export class Upload {
  @PrimaryGeneratedColumn()
  id: number

  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
    transformer: {
      to(value: Date): number {
        return value ? value.getTime() : null;
      },
      from(value: number) {
        // 将UTC时间转换为北京时间
        return utcToBeijing(value)
      },
    },
  })
  createDate: Date
  @Column({
    comment: '图片url',
    length: 100
  })
  url: string

  @Column({
    comment: '图片分类, 1风景 2美食 3日常 4艺术 5说说'
  })
  type: number

  @Column({
    comment: '用户id',
  })
  userId: number

  @Column({
    comment: 'ip'
  })
  ip: string
}
